package com.konsung.ksdc.manager.advice;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.konsung.ksdc.R;
import com.konsung.ksdc.bean.netbean.ReplyNetBean;
import com.konsung.ksdc.config.MyApplication;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/3/24 0024.
 */
public class ReplyDetailAdapter extends BaseAdapter {
    private List<ReplyNetBean> mDatas = new ArrayList<>();

    /**
     * 构造方法
     * @param replys 回复数据
     */
    public ReplyDetailAdapter(List<ReplyNetBean> replys) {
        mDatas = replys;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ReplyNetBean bean = mDatas.get(position);

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(MyApplication.getContext())
                    .inflate(R.layout
                    .item_listview_reply_detail, null);
            ButterKnife.bind(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        String replyDate = bean.getReplyDate();
        String str = replyDate.replace("&", "  ");
        String date = str.replace("_", ":");
        holder.tvDate.setText(date);
        holder.tvContent.setText(bean.getReplyContent());

        return convertView;
    }

    /**
     * 内部类
     */
    static class ViewHolder {
        @Bind(R.id.tv_date)
        TextView tvDate;
        @Bind(R.id.tv_content)
        TextView tvContent;
    }

    /**
     * 设置数据
     * @param replies 数据
     */
    public void setDatas(List<ReplyNetBean> replies) {
        mDatas = replies;
        notifyDataSetChanged();
    }
}
